package kr.ac.mlb.action;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import kr.ac.mlb.dao.ListDao;
import kr.ac.mlb.mvc.Action;
import kr.ac.mlb.mvc.HttpUtil;
import kr.ac.mlb.vo.ContentVo;

public class ListAction extends Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		// TODO Auto-generated method stub
		
		String jsonStr = "";

		//리스트가져오기
		ListDao dao = new ListDao();
		List<ContentVo> list = dao.getList();
		
		int length = list.size();
		
		System.out.println(length);
		
		jsonStr += "{";
		jsonStr += "\"AnnoymousSNS\":[";
		
		for(int i = 0; i < length; i++){
			jsonStr += "{";
			jsonStr += 		"\"content\":\"" + list.get(i).getContent() + "\",";
			jsonStr +=		"\"time\":\"" + list.get(i).getTime() + "\"";
			jsonStr += "}";
			
			if(i < length - 1) jsonStr += ",";
		}
		
		jsonStr += "]";
		jsonStr += "}";
		
//		System.out.println(jsonStr);
		
		request.setAttribute("json", jsonStr);
	}

}
